package com.woniuxy.oa.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.woniuxy.oa.entity.EmployeeMsg;
import com.woniuxy.oa.entity.PageMsg;
import com.woniuxy.oa.service.AddressService;

@Controller
public class PageAddressController {
	
	@Autowired
	AddressService addressService;
	
	@RequestMapping("/top")
	public String topController() {
		return "system/index/top";
	}
	
	@RequestMapping("/menu")
	public String menuController() {
		return "system/index/menu";
	}
	
	@RequestMapping("/modifyEmployee")
	public String modify(int id,HttpSession session) {
		//因为查询信息方法参数是employeeMsg，因此创建该对象，查询出来的结果取第一条。
		EmployeeMsg employeeMsg=new EmployeeMsg(id,null,null,null);
		PageMsg pageMsg = addressService.selectEmployeeMsgByCondition(employeeMsg, 1, 10);
		//取出第一条（只有一条）记录，将其存入model，在修改页面展示
		employeeMsg=pageMsg.getEmployeeMsgs().get(0);
		//存入session，在修改判断格式不正确时可以返回时显示
		session.setAttribute("employeeMsg", employeeMsg);
		return "modify";
	}
	
	
	@RequestMapping("/addAddress")
	public String addAddress(Model model) {
		//从主表中查询出所有id，用于前端显示要添加的员工
		List<Integer> ids=new ArrayList<Integer>();
		ids=addressService.selectAllId();
		//将所有id存入返回给前端
		model.addAttribute("ids", ids);
		return "addAddress";
	}
	
	
	

	
	
	
	
}
